<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="author" content="esy">
    
    <meta name="description" content="esy">
    
    
    
    
    
    
    <title>HRV的30s特征提取 | ESY</title>
    <link href="https://esyyes.github.io" rel="prefetch" />

    
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/aos.css">
<link rel="stylesheet" href="/css/style.css">

    
<script src="/js/jquery.min.js"></script>

    
<script src="/js/bootstrap.min.js"></script>

    
<script src="/js/aos.js"></script>

    
<script src="/js/highslide/highslide-full.min.js"></script>

    
<link rel="stylesheet" href="/js/highslide/highslide.css">

    <style type="text/css">
        @media (max-width: 768px) {
            body {
                background-color: #f0f0f0;
                background: url('/imgs/xsbg.gif');
                background-attachment: fixed;
            }
        }
    </style>
    
    <!--<script type="text/javascript">
      if (document.images) {
        var avatar = new Image();
        avatar.src = '/imgs/avatar.jpg'
        var previews = 'preview1.jpg,preview2.jpg,preview3.jpg,preview4.jpg'.split(',')
        var previewsPreLoad = []
        for(var i = 0; i < length; i++) {
          previewsPreLoad.push(new Image())
          previewsPreLoad[previewsPreLoad.length - 1].src = '/imgs/preview' + previews[i]
        }
      }
    </script>-->
<meta name="generator" content="Hexo 5.2.0"></head>
<body>
    <!-- 背景轮播图功能 -->
    <section class="hidden-xs">
    <ul class="cb-slideshow">
        <li><span>天若</span></li>
        <li><span>有情</span></li>
        <li><span>天亦老</span></li>
        <li><span>我为</span></li>
        <li><span>长者</span></li>
        <li><span>续一秒</span></li>
    </ul>
</section>
    <!-- 欧尼酱功能, 谁用谁知道 -->
    
    <div class="gal-menu gal-dropdown">
    <div class="circle" id="gal">
        <div class="ring">
            <a href="https://esyyes.github.io" class="menuItem" style="left: 50%; top: 15%;">首页</a>
            
            <a class="menuItem" style="left: 80.3109%; top: 32.5%;">下一页</a>
            
            <a href="/archives" class="menuItem" style="left: 80.3109%; top: 67.5%;">归档</a>
            <a href="/about" class="menuItem" style="left: 50%; top: 85%;">关于</a>
            <a href="/message" class="menuItem" style="left: 19.6891%; top: 67.5%;">留言板</a>

            
            <a class="menuItem" style="left: 19.6891%; top: 32.5%;">上一页</a>
            
        </div>
        <audio id="audio" src="/imgs/oni.mp3"></audio>
    </div>
</div>
    
    <header class="navbar navbar-inverse" id="gal-header">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed"
                    data-toggle="collapse" data-target=".bs-navbar-collapse"
                    aria-expanded="false">
                <span class="fa fa-lg fa-reorder"></span>
            </button>
            <a href="https://esyyes.github.io">
                
                <style>
                    #gal-header .navbar-brand {
                        height: 54px;
                        line-height: 24px;
                        font-size: 28px;
                        opacity: 1;
                        background-color: rgba(0,0,0,0);
                        text-shadow: 0 0 5px #fff,0 0 10px #fff,0 0 15px #fff,0 0 20px #228DFF,0 0 35px #228DFF,0 0 40px #228DFF,0 0 50px #228DFF,0 0 75px #228DFF;
                    }
                </style>
                <!-- 这里使用文字(navbar_text or config.title) -->
                <div class="navbar-brand">ESY</div>
                
            </a>
        </div>
        <div class="collapse navbar-collapse bs-navbar-collapse">
            <ul class="nav navbar-nav" id="menu-gal">
                
                
                <li class="">
                    <a href="/">
                        <i class="fa fa-home"></i>首页
                    </a>
                </li>
                
                
                
                <li class="">
                    <a href="/archives">
                        <i class="fa fa-archive"></i>归档
                    </a>
                </li>
                
                
                
                
                <li class="dropdown">
                    <!-- TODO 添加hover dropdown效果 -->
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false" data-hover="dropdown">
                        <i class="fa fa-list"></i>分类
                    </a>
                    <ul class="dropdown-menu">
                        
                        
                        <li>
                            <a href="/categories/py-study/">py_study</a>
                        </li>
                        
                        <li>
                            <a href="/categories/nlp/">nlp</a>
                        </li>
                        
                        <li>
                            <a href="/categories/Graduation-work/">Graduation work</a>
                        </li>
                        
                        <li>
                            <a href="/categories/work/">work</a>
                        </li>
                        
                        <li>
                            <a href="/categories/hexo/">hexo</a>
                        </li>
                        
                        <li>
                            <a href="/categories/hexo%E5%AE%8C%E5%96%84/">-hexo完善</a>
                        </li>
                        
                        
                        <li>
                            <a href="/categories">...</a>
                        </li>
                        
                        
                    </ul>
                </li>
                
                
                
                
                
                <li class="dropdown">
                    <!-- TODO 添加hover dropdown效果 -->
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false" data-hover="dropdown">
                        <i class="fa fa-tags"></i>标签
                    </a>
                    <ul class="dropdown-menu">
                        
                        
                        <li>
                            <a href="/tags/py-study/">py_study</a>
                        </li>
                        
                        <li>
                            <a href="/tags/nlp/">nlp</a>
                        </li>
                        
                        <li>
                            <a href="/tags/Graduation-work/">Graduation work</a>
                        </li>
                        
                        <li>
                            <a href="/tags/work/">work</a>
                        </li>
                        
                        <li>
                            <a href="/tags/hexo/">hexo</a>
                        </li>
                        
                        <li>
                            <a href="/tags/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">-个人博客搭建</a>
                        </li>
                        
                        
                        <li>
                            <a href="/tags">...</a>
                        </li>
                        
                        
                    </ul>
                </li>
                
                
                
                
                <li class="">
                    <a href="/about">
                        <i class="fa fa-user"></i>关于我
                    </a>
                </li>
                
                
            </ul>
        </div>
    </div>
</header>
    <div id="gal-body">
        <div class="container">
            <div class="row">
                <div class="col-md-8 gal-right" id="mainstay">
                    
<article class="article well article-body" id="article">
    <div class="breadcrumb">
        <i class="fa fa-home"></i>
        <a href="https://esyyes.github.io">ESY</a>
        >
        <span>HRV的30s特征提取</span>
    </div>
    <!-- 大型设备详细文章 -->
    <div class="hidden-xs">
        <div class="title-article">
            <h1>
                <a href="/2020/06/08/python%20work/HRV%E7%9A%8430s%E7%89%B9%E5%BE%81%E6%8F%90%E5%8F%96/">HRV的30s特征提取</a>
            </h1>
        </div>
        <div class="tag-article">
            
            <span class="label label-gal">
                <i class="fa fa-tags"></i>
                
                <a href="/tags/work/">work</a>
                
            </span>
            
            <span class="label label-gal">
                <i class="fa fa-calendar"></i> 2020-06-08
            </span>
            
        </div>
    </div>
    <!-- 小型设备详细文章 -->
    <div class="visible-xs">
        <center>
            <div class="title-article">
                <h4>
                    <a href="/2020/06/08/python%20work/HRV%E7%9A%8430s%E7%89%B9%E5%BE%81%E6%8F%90%E5%8F%96/">HRV的30s特征提取</a>
                </h4>
            </div>
            <p>
                <i class="fa fa-calendar"></i> 2020-06-08
            </p>
            <p>
                
                <i class="fa fa-tags"></i>
                
                <a href="/tags/work/">work</a>
                
                
                
            </p>
        </center>
    </div>
    <div class="content-article">
        <h1 id="HRV的30s特征提取"><a href="#HRV的30s特征提取" class="headerlink" title="HRV的30s特征提取"></a>HRV的30s特征提取</h1><p> slp03和slp60数据中有一段数据遗失了ecg——r,</p>
<p>slp03消除174-194之间的数据</p>
<p>slp60消除538 &lt; i &lt; 549之间的数据</p>
<p> 标签这一部分全是w，可以删除</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/6/2</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># slp60数据到时需要加0.7或者其他左右，没有经过预处理后，就不会出现复数，所以peaks中就不需要abs，加起也好</span></span><br><span class="line"><span class="keyword">import</span> wfdb</span><br><span class="line"><span class="keyword">from</span> wfdb <span class="keyword">import</span> processing</span><br><span class="line"><span class="comment"># import numpy as np</span></span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">import</span> warnings</span><br><span class="line"><span class="keyword">from</span> peaks_time_features <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> time_domain <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> frequency_domain <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> HRV_interp1 <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> nonliner_domain <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> eliminate_outliers <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"><span class="comment"># 忽略警告</span></span><br><span class="line">warnings.filterwarnings(<span class="string">&quot;ignore&quot;</span>)</span><br><span class="line">test = <span class="built_in">input</span>(<span class="string">&#x27;请输入文件名：&#x27;</span>)</span><br><span class="line"><span class="comment"># test = &#x27;slp03&#x27;</span></span><br><span class="line">record = wfdb.rdrecord(<span class="string">&#x27;F:/slpdb_data/mitdata&#x27;</span> + <span class="string">&#x27;/%s&#x27;</span> % test, channels=[<span class="number">0</span>])</span><br><span class="line">annotation = wfdb.rdann(<span class="string">&#x27;F:/slpdb_data/mitdata&#x27;</span> + <span class="string">&#x27;/%s&#x27;</span> % test, <span class="string">&#x27;ecg&#x27;</span>)</span><br><span class="line"></span><br><span class="line">ecg_signal = record.p_signal</span><br><span class="line">ecg_locs = annotation.sample.tolist()</span><br><span class="line">ecg_locs.pop(<span class="number">0</span>)</span><br><span class="line">min_bpm = <span class="number">40</span></span><br><span class="line">max_bpm = <span class="number">200</span></span><br><span class="line"></span><br><span class="line">search_radius = <span class="built_in">int</span>(record.fs * <span class="number">60</span> / max_bpm)</span><br><span class="line">ecg_r_locs1 = processing.correct_peaks(ecg_signal[:, <span class="number">0</span>], peak_inds=ecg_locs, search_radius=search_radius,</span><br><span class="line">                                       smooth_window_size=<span class="number">100</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># ecg_r_locs异常点处理</span></span><br><span class="line">ecg_r_locs = eliminate(ecg_r_locs1)</span><br><span class="line"><span class="comment"># ecg_r_peaks峰值点获取</span></span><br><span class="line">ecg_r_peaks = [ecg_signal[<span class="built_in">int</span>(ecg_r_locs[i])][<span class="number">0</span>] <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(ecg_r_locs))]</span><br><span class="line"></span><br><span class="line">all_RR_30s = []</span><br><span class="line">all_locs_30s = []</span><br><span class="line">all_peaks_30s = []</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">int</span>(record.sig_len/record.fs/<span class="number">30</span> - <span class="number">1</span>)):</span><br><span class="line">    RR_30s = []</span><br><span class="line">    locs_30s = []</span><br><span class="line">    peaks_30s = []</span><br><span class="line">    <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(ecg_r_locs)):</span><br><span class="line">        <span class="keyword">if</span> (<span class="number">30</span>*record.fs*i) &lt;= ecg_r_locs[j] &lt;= (<span class="number">30</span>*record.fs*(i+<span class="number">1</span>)):</span><br><span class="line">            locs_30s.append(ecg_r_locs[j])</span><br><span class="line">            RR_30s.append((ecg_r_locs[j+<span class="number">1</span>] - ecg_r_locs[j]) * <span class="number">4</span>)</span><br><span class="line">            peaks_30s.append(ecg_r_peaks[j])</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">    RR_30s.pop()</span><br><span class="line">    all_RR_30s.append(RR_30s)</span><br><span class="line">    <span class="keyword">del</span> locs_30s[<span class="number">0</span>]</span><br><span class="line">    all_locs_30s.append(locs_30s)</span><br><span class="line">    all_peaks_30s.append(peaks_30s)</span><br><span class="line"></span><br><span class="line"><span class="comment"># ECG_R</span></span><br><span class="line">peaks_features = [peaks_time_feature(all_peaks_30s[i]) <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(all_peaks_30s))]</span><br><span class="line"><span class="comment"># HRV</span></span><br><span class="line">hrv_time = [time_features(all_RR_30s[i]) <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(all_RR_30s))]</span><br><span class="line">hrv_freq = [getfreq(resample(hrv_interp1(all_locs_30s[i], all_RR_30s[i], <span class="number">1</span>), <span class="number">250</span>, <span class="number">4</span>)) <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(all_RR_30s))]</span><br><span class="line">hrv_nonl = [non_linear(np.array(all_RR_30s[i])) <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(all_RR_30s))]</span><br><span class="line">features = [peaks_features[i] + hrv_time[i] + hrv_freq[i] + hrv_nonl[i] <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(all_RR_30s))]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 保存为excel</span></span><br><span class="line">feature = pd.DataFrame(features, columns=[<span class="string">&#x27;p_max&#x27;</span>, <span class="string">&#x27;p_min&#x27;</span>, <span class="string">&#x27;p_mean&#x27;</span>, <span class="string">&#x27;p_median&#x27;</span>, <span class="string">&#x27;p_SDNN&#x27;</span>, <span class="string">&#x27;p_var&#x27;</span>,</span><br><span class="line">                                          <span class="string">&#x27;p_Peaks&#x27;</span>, <span class="string">&#x27;p_RMSSD&#x27;</span>, <span class="string">&#x27;p_kurt&#x27;</span>, <span class="string">&#x27;p_skew&#x27;</span>, <span class="string">&#x27;p_wave_factor&#x27;</span>,</span><br><span class="line">                                          <span class="string">&#x27;p_peak_factor&#x27;</span>, <span class="string">&#x27;p_Impulse_factor&#x27;</span>, <span class="string">&#x27;p_Margin_factor&#x27;</span>, <span class="string">&#x27;p_RMS&#x27;</span>,</span><br><span class="line">                                          <span class="string">&#x27;R_mean&#x27;</span>, <span class="string">&#x27;R_SDNN&#x27;</span>, <span class="string">&#x27;R_SDSD&#x27;</span>, <span class="string">&#x27;NN50&#x27;</span>, <span class="string">&#x27;pNN50&#x27;</span>, <span class="string">&#x27;NN20&#x27;</span>, <span class="string">&#x27;pNN20&#x27;</span>, <span class="string">&#x27;R_RMSSD&#x27;</span>,</span><br><span class="line">                                          <span class="string">&#x27;R_median&#x27;</span>, <span class="string">&#x27;R_NUM&#x27;</span>, <span class="string">&#x27;R_CVSD&#x27;</span>, <span class="string">&#x27;R_CV&#x27;</span>, <span class="string">&#x27;HR_mean&#x27;</span>, <span class="string">&#x27;HR_max&#x27;</span>, <span class="string">&#x27;HR_min&#x27;</span>, <span class="string">&#x27;HR_std&#x27;</span>,</span><br><span class="line">                                          <span class="string">&#x27;LF&#x27;</span>, <span class="string">&#x27;HF&#x27;</span>, <span class="string">&#x27;LF_HF&#x27;</span>, <span class="string">&#x27;LFnu&#x27;</span>, <span class="string">&#x27;HFnu&#x27;</span>, <span class="string">&#x27;total&#x27;</span>, <span class="string">&#x27; VLF&#x27;</span>, <span class="string">&#x27;sd1&#x27;</span>, <span class="string">&#x27;sd2&#x27;</span>, <span class="string">&#x27;sd2/sd1&#x27;</span>,</span><br><span class="line">                                          <span class="string">&#x27;csi10&#x27;</span>, <span class="string">&#x27;cvi&#x27;</span>, <span class="string">&#x27;Modified_CSI10&#x27;</span>, <span class="string">&#x27;apen&#x27;</span>, <span class="string">&#x27;spen&#x27;</span>, <span class="string">&#x27;lle&#x27;</span>, <span class="string">&#x27;sampen&#x27;</span>])</span><br><span class="line">num = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">&#x27;请输入特征的名字:&#x27;</span>))</span><br><span class="line">feature.to_excel(<span class="string">&#x27;slp&#x27;</span> + <span class="string">&#x27;%d&#x27;</span> % num + <span class="string">&quot;.xlsx&quot;</span>)</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">all_peaks_30s = []</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">int</span>(record.sig_len/record.fs/<span class="number">30</span> - <span class="number">1</span>)):</span><br><span class="line">    <span class="keyword">if</span> <span class="number">538</span> &lt; i &lt; <span class="number">549</span>:slp60</span><br><span class="line">        <span class="number">174</span><span class="number">-194</span> slp03</span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        RR_30s = []</span><br><span class="line">        locs_30s = []</span><br><span class="line">        peaks_30s = []</span><br><span class="line">        <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(ecg_r_locs)):</span><br><span class="line">            <span class="keyword">if</span> (<span class="number">30</span>*record.fs*i) &lt;= ecg_r_locs[j] &lt;= (<span class="number">30</span>*record.fs*(i+<span class="number">1</span>)):</span><br><span class="line">                locs_30s.append(ecg_r_locs[j])</span><br><span class="line">                RR_30s.append((ecg_r_locs[j+<span class="number">1</span>] - ecg_r_locs[j]) * <span class="number">4</span>)</span><br><span class="line">                peaks_30s.append(ecg_r_peaks[j])</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                <span class="keyword">pass</span></span><br><span class="line">        RR_30s.pop()</span><br><span class="line">        all_RR_30s.append(RR_30s)</span><br><span class="line">        <span class="keyword">del</span> locs_30s[<span class="number">0</span>]</span><br><span class="line">        all_locs_30s.append(locs_30s)</span><br><span class="line">        all_peaks_30s.append(peaks_30s)</span><br></pre></td></tr></table></figure>

<h2 id="消除异常点"><a href="#消除异常点" class="headerlink" title="消除异常点"></a>消除异常点</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/6/8</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"></span><br><span class="line"><span class="comment"># RR间期获取</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">RR_rr</span>(<span class="params">locs1</span>):</span></span><br><span class="line">    <span class="keyword">return</span> [locs1[i+<span class="number">1</span>]-locs1[i] <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(locs1) - <span class="number">1</span>)]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 得到19个RR间期的均值</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">MRR</span>(<span class="params">x</span>):</span></span><br><span class="line">    <span class="keyword">return</span> [np.mean(x[i:i+<span class="number">19</span>]) <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(x) - <span class="number">19</span>)]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 消除过检</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Eliminate_check</span>(<span class="params">locs1</span>):</span></span><br><span class="line">    RR_lou = []</span><br><span class="line">    num = <span class="number">0</span></span><br><span class="line">    RR_locs_lou = []</span><br><span class="line">    RR = RR_rr(locs1)</span><br><span class="line">    mRR = MRR(RR)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(RR)):</span><br><span class="line">        <span class="keyword">if</span> i &lt; <span class="number">10</span>:</span><br><span class="line">            <span class="keyword">if</span> RR[i] &lt; (<span class="number">0.55</span> * mRR[<span class="number">0</span>]):</span><br><span class="line">                RR2 = RR[i] + RR[i<span class="number">-1</span>]</span><br><span class="line">                num += <span class="number">1</span></span><br><span class="line">                RR_lou.pop(i - num)</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">                RR_locs_lou.pop(i - num)</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                RR2 = RR[i]</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">        <span class="keyword">elif</span> i &gt; (<span class="built_in">len</span>(RR) - <span class="number">10</span>):</span><br><span class="line">            <span class="keyword">if</span> RR[i] &lt; (<span class="number">0.55</span> * mRR[<span class="built_in">len</span>(mRR) - <span class="number">1</span>]):</span><br><span class="line">                RR2 = RR[i] + RR[i - <span class="number">1</span>]</span><br><span class="line">                num = num + <span class="number">1</span></span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">                RR_lou.pop(i - num)</span><br><span class="line">                RR_locs_lou.pop(i - num)</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                RR2 = RR[i]</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">if</span> RR[i] &lt; (<span class="number">0.55</span> * mRR[i - <span class="number">10</span>]):</span><br><span class="line">                RR2 = RR[i] + RR[i - <span class="number">1</span>]</span><br><span class="line">                num = num + <span class="number">1</span></span><br><span class="line">                RR_lou.pop(i - num)</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">                RR_locs_lou.pop(i - num)</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                RR2 = RR[i]</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">        RR_lou.append(RR2)</span><br><span class="line">        RR_locs_lou.append(locs2)</span><br><span class="line">    RR_locs_lou.insert(<span class="number">0</span>, locs1[<span class="number">0</span>])</span><br><span class="line">    <span class="keyword">return</span> RR_locs_lou</span><br><span class="line"></span><br><span class="line"><span class="comment"># 消除漏检</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Eliminate_LOW</span>(<span class="params">locs</span>):</span></span><br><span class="line">    locs1 = Eliminate_check(locs)</span><br><span class="line">    RR = RR_rr(locs1)</span><br><span class="line">    mRR = MRR(RR)</span><br><span class="line">    i = <span class="number">0</span></span><br><span class="line">    k = <span class="number">0</span></span><br><span class="line">    RR_guo = []</span><br><span class="line">    RR_locs_guo = []</span><br><span class="line">    <span class="keyword">while</span> i &lt; <span class="built_in">len</span>(RR):</span><br><span class="line">        <span class="keyword">if</span> i &lt; <span class="number">10</span>:</span><br><span class="line">            <span class="keyword">if</span> RR[i] &gt; (<span class="number">1.55</span> * mRR[<span class="number">0</span>]):</span><br><span class="line">                m = <span class="built_in">int</span>(<span class="built_in">round</span>(RR[i] / mRR[<span class="number">0</span>]))</span><br><span class="line">                RR3 = RR[i] / m</span><br><span class="line">                RR_guo[(i + k):(i + k)] = (m - <span class="number">1</span>) * [RR3]</span><br><span class="line">                cs = []</span><br><span class="line">                <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(m - <span class="number">1</span>):</span><br><span class="line">                    cs1 = locs1[i] + (j + <span class="number">1</span>) * RR3</span><br><span class="line">                    cs.append(cs1)</span><br><span class="line">                RR_locs_guo.extend(cs)</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">                k = k + m</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                RR3 = RR[i]</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line"></span><br><span class="line">        <span class="keyword">elif</span> i &gt; (<span class="built_in">len</span>(RR) - <span class="number">10</span>):</span><br><span class="line">            <span class="keyword">if</span> RR[i] &gt; (<span class="number">1.55</span> * mRR[<span class="built_in">len</span>(mRR) - <span class="number">1</span>]):</span><br><span class="line">                m = <span class="built_in">int</span>(<span class="built_in">round</span>(RR[i] / mRR[<span class="built_in">len</span>(mRR) - <span class="number">1</span>]))</span><br><span class="line">                RR3 = RR[i] / m</span><br><span class="line">                RR_guo[(i + k):(i + k)] = (m - <span class="number">1</span>) * [RR3]</span><br><span class="line">                cs = []</span><br><span class="line">                <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(m - <span class="number">1</span>):</span><br><span class="line">                    cs1 = locs1[i] + (j + <span class="number">1</span>) * RR3</span><br><span class="line">                    cs.append(cs1)</span><br><span class="line">                RR_locs_guo.extend(cs)</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">                k = k + m</span><br><span class="line"></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                RR3 = RR[i]</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line"></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">if</span> RR[i] &gt; (<span class="number">1.55</span> * mRR[i - <span class="number">10</span>]):</span><br><span class="line">                m = <span class="built_in">int</span>(<span class="built_in">round</span>(RR[i] / mRR[i]))</span><br><span class="line">                RR3 = RR[i] / m</span><br><span class="line">                RR_guo[(i + k):(i + k)] = (m - <span class="number">1</span>) * [RR3]</span><br><span class="line">                cs = []</span><br><span class="line">                <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(m - <span class="number">1</span>):</span><br><span class="line">                    cs1 = locs1[i] + (j + <span class="number">1</span>) * RR3</span><br><span class="line">                    cs.append(cs1)</span><br><span class="line">                RR_locs_guo.extend(cs)</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">                k = k + m</span><br><span class="line"></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                RR3 = RR[i]</span><br><span class="line">                locs2 = locs1[i + <span class="number">1</span>]</span><br><span class="line">        i += <span class="number">1</span></span><br><span class="line">        RR_locs_guo.append(locs2)</span><br><span class="line">        RR_guo.append(RR3)</span><br><span class="line">    RR_locs_guo.insert(<span class="number">0</span>, locs1[<span class="number">0</span>])</span><br><span class="line">    <span class="keyword">return</span> RR_locs_guo</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">eliminate</span>(<span class="params">locs1</span>):</span></span><br><span class="line">    c = Eliminate_LOW(Eliminate_check(locs1))</span><br><span class="line">    <span class="keyword">return</span> c</span><br></pre></td></tr></table></figure>

<h2 id="peaks的时域特征"><a href="#peaks的时域特征" class="headerlink" title="peaks的时域特征"></a>peaks的时域特征</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/6/3</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># R峰值的时域特征分析</span></span><br><span class="line"><span class="keyword">import</span> math</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">from</span> scipy <span class="keyword">import</span> stats</span><br><span class="line"></span><br><span class="line"><span class="comment"># 裕度因子</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">margin_factor</span>(<span class="params">x</span>):</span></span><br><span class="line">    <span class="built_in">sum</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(x) - <span class="number">1</span>):</span><br><span class="line">        <span class="built_in">sum</span> += math.sqrt(x[i])</span><br><span class="line">    mean = np.mean(<span class="built_in">sum</span>)</span><br><span class="line">    <span class="keyword">return</span> mean**<span class="number">2</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 差值均方根</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_RMSSD</span>(<span class="params">x</span>):</span></span><br><span class="line">    <span class="built_in">sum</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(x) - <span class="number">1</span>):</span><br><span class="line">        <span class="built_in">sum</span> += (x[i+<span class="number">1</span>] - x[i])**<span class="number">2</span></span><br><span class="line">    <span class="keyword">return</span> math.sqrt(<span class="built_in">sum</span>/(<span class="built_in">len</span>(x) - <span class="number">1</span>))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 均方根</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_rms</span>(<span class="params">x</span>):</span></span><br><span class="line">    <span class="built_in">sum</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(x) - <span class="number">1</span>):</span><br><span class="line">        <span class="built_in">sum</span> += (x[i])**<span class="number">2</span></span><br><span class="line">    <span class="keyword">return</span> math.sqrt(<span class="built_in">sum</span> / (<span class="built_in">len</span>(x)<span class="number">-1</span>))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">peaks_time_feature</span>(<span class="params">f</span>):</span></span><br><span class="line">    x = <span class="built_in">abs</span>(np.array(f))</span><br><span class="line">    <span class="comment"># 最大值</span></span><br><span class="line">    p_max = x.<span class="built_in">max</span>()</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 最小值</span></span><br><span class="line">    p_min = x.<span class="built_in">min</span>()</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 均值：</span></span><br><span class="line">    p_mean = x.mean()</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 中位数</span></span><br><span class="line">    p_median = np.median(x)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 标准差</span></span><br><span class="line">    SDNN = x.std()</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 方差</span></span><br><span class="line">    p_var = x.var()</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 峰峰值</span></span><br><span class="line">    p_peaks = p_max - p_min</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 差值均方根</span></span><br><span class="line">    RMSSD = get_RMSSD(x)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 峭度/峰度</span></span><br><span class="line">    p_kurt = stats.kurtosis(x)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 偏度</span></span><br><span class="line">    p_skew = stats.skew(x)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 波形因子</span></span><br><span class="line">    p_wave_factor = RMSSD / p_mean</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 峰值因子</span></span><br><span class="line">    p_peak_factor = p_peaks / RMSSD</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 脉冲因子</span></span><br><span class="line">    p_impulse_factor = p_peaks / p_mean</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 裕度因子</span></span><br><span class="line">    p_margin_factor = p_peaks / margin_factor(x)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 均方根</span></span><br><span class="line">    p_RMS = get_rms(x)</span><br><span class="line"></span><br><span class="line">    list_time_features = [p_max, p_min, p_mean, p_median, SDNN, p_var, p_peaks, RMSSD, p_kurt, p_skew,</span><br><span class="line">                          p_wave_factor, p_peak_factor, p_impulse_factor, p_margin_factor, p_RMS]</span><br><span class="line">    <span class="keyword">return</span> list_time_features</span><br></pre></td></tr></table></figure>

<h2 id="HRV的时域特征"><a href="#HRV的时域特征" class="headerlink" title="HRV的时域特征"></a>HRV的时域特征</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/6/8</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> hrvanalysis <span class="keyword">import</span> get_time_domain_features</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">time_features</span>(<span class="params">x</span>):</span></span><br><span class="line">    A = get_time_domain_features(x)</span><br><span class="line">    RR_mean = A[<span class="string">&#x27;mean_nni&#x27;</span>]</span><br><span class="line">    SDNN = A[<span class="string">&#x27;sdnn&#x27;</span>]</span><br><span class="line">    SDSD = A[<span class="string">&#x27;sdsd&#x27;</span>]</span><br><span class="line">    NN50 = A[<span class="string">&#x27;nni_50&#x27;</span>]</span><br><span class="line">    PNN50 = A[<span class="string">&#x27;pnni_50&#x27;</span>]</span><br><span class="line">    NN20 = A[<span class="string">&#x27;nni_20&#x27;</span>]</span><br><span class="line">    PNN20 = A[<span class="string">&#x27;pnni_20&#x27;</span>]</span><br><span class="line">    RMSSD = A[<span class="string">&#x27;rmssd&#x27;</span>]</span><br><span class="line">    RR_median = A[<span class="string">&#x27;median_nni&#x27;</span>]</span><br><span class="line">    NUM = A[<span class="string">&#x27;range_nni&#x27;</span>]</span><br><span class="line">    CVSD = A[<span class="string">&#x27;cvsd&#x27;</span>]</span><br><span class="line">    RR_CV = A[<span class="string">&#x27;cvnni&#x27;</span>]</span><br><span class="line">    HR_mean = A[<span class="string">&#x27;mean_hr&#x27;</span>]</span><br><span class="line">    HR_max = A[<span class="string">&#x27;max_hr&#x27;</span>]</span><br><span class="line">    HR_min = A[<span class="string">&#x27;min_hr&#x27;</span>]</span><br><span class="line">    HR_std = A[<span class="string">&#x27;std_hr&#x27;</span>]</span><br><span class="line">    ALL = [RR_mean, SDNN, SDSD, NN50, PNN50, NN20, PNN20, RMSSD, RR_median, NUM, CVSD, RR_CV, HR_mean, HR_max,</span><br><span class="line">           HR_min, HR_std]</span><br><span class="line">    <span class="keyword">return</span> ALL</span><br></pre></td></tr></table></figure>

<h2 id="插值并重采样"><a href="#插值并重采样" class="headerlink" title="插值并重采样"></a>插值并重采样</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/6/8</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> scipy.interpolate <span class="keyword">as</span> spi</span><br><span class="line"></span><br><span class="line"><span class="comment"># 插值</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">hrv_interp1</span>(<span class="params">x, y, s</span>):</span></span><br><span class="line">    x_new = np.linspace(x[<span class="number">0</span>], x[<span class="built_in">len</span>(x) - <span class="number">1</span>], <span class="number">7500</span> * s)  <span class="comment"># 新的插值区间及其点的个数</span></span><br><span class="line">    ipo3 = spi.splrep(x, y, k=<span class="number">3</span>)  <span class="comment"># 样本点导入，生成参数</span></span><br><span class="line">    hrv_interpolation = spi.splev(x_new, ipo3)  <span class="comment"># 根据观测点和样条参数，生成插值</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> hrv_interpolation</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 重采样</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">resample</span>(<span class="params">input_signal, src_fs, tar_fs</span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    :param input_signal:输入信号</span></span><br><span class="line"><span class="string">    :param src_fs:输入信号采样率</span></span><br><span class="line"><span class="string">    :param tar_fs:输出信号采样率</span></span><br><span class="line"><span class="string">    :return:输出信号</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line">    dtype = input_signal.dtype</span><br><span class="line">    audio_len = <span class="built_in">len</span>(input_signal)</span><br><span class="line">    audio_time_max = <span class="number">1.0</span> * audio_len / src_fs</span><br><span class="line">    src_time = <span class="number">1.0</span> * np.linspace(<span class="number">0</span>, audio_len, audio_len) / src_fs</span><br><span class="line">    tar_time = <span class="number">1.0</span> * np.linspace(<span class="number">0</span>, np.<span class="built_in">int</span>(audio_time_max*tar_fs), np.<span class="built_in">int</span>(audio_time_max*tar_fs)) / tar_fs</span><br><span class="line">    output_signal = np.interp(tar_time, src_time, input_signal).astype(dtype)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> output_signal</span><br></pre></td></tr></table></figure>



<h2 id="HRV的频域特征"><a href="#HRV的频域特征" class="headerlink" title="HRV的频域特征"></a>HRV的频域特征</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/6/8</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> hrvanalysis <span class="keyword">import</span> get_frequency_domain_features</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">getfreq</span>(<span class="params">x</span>):</span></span><br><span class="line">    <span class="built_in">all</span> = get_frequency_domain_features(x)</span><br><span class="line">    LF = <span class="built_in">all</span>[<span class="string">&#x27;lf&#x27;</span>]</span><br><span class="line">    HF = <span class="built_in">all</span>[<span class="string">&#x27;hf&#x27;</span>]</span><br><span class="line">    LF_HF = <span class="built_in">all</span>[<span class="string">&#x27;lf_hf_ratio&#x27;</span>]</span><br><span class="line">    LFnu = <span class="built_in">all</span>[<span class="string">&#x27;lfnu&#x27;</span>]</span><br><span class="line">    HFnu = <span class="built_in">all</span>[<span class="string">&#x27;hfnu&#x27;</span>]</span><br><span class="line">    total = <span class="built_in">all</span>[<span class="string">&#x27;total_power&#x27;</span>]</span><br><span class="line">    VLF = <span class="built_in">all</span>[<span class="string">&#x27;vlf&#x27;</span>]</span><br><span class="line">    freqs = [LF, HF, LF_HF, LFnu, HFnu, total, VLF]</span><br><span class="line">    <span class="keyword">return</span> freqs</span><br></pre></td></tr></table></figure>

<h2 id="HRV的非线性特征"><a href="#HRV的非线性特征" class="headerlink" title="HRV的非线性特征"></a>HRV的非线性特征</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/6/8</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> hrvanalysis <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> non_features <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">SD1</span>(<span class="params">x</span>):</span></span><br><span class="line">    sd = [x[i+<span class="number">1</span>] - x[i] <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(x)<span class="number">-1</span>)]</span><br><span class="line">    <span class="keyword">return</span> np.std(sd) / np.sqrt(<span class="number">2</span>)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">SD2</span>(<span class="params">x</span>):</span></span><br><span class="line">    sd = [x[i+<span class="number">1</span>] + x[i] <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(x)<span class="number">-1</span>)]</span><br><span class="line">    <span class="keyword">return</span> np.std(sd) / np.sqrt(<span class="number">2</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">non_linear5</span>(<span class="params">x</span>):</span></span><br><span class="line">    RR_sd1 = SD1(x)</span><br><span class="line">    RR_sd2 = SD2(x)</span><br><span class="line">    RR_csi10 = csi(x, <span class="number">10</span>)</span><br><span class="line">    RR_csi30 = csi(x, <span class="number">30</span>)</span><br><span class="line">    RR_csi50 = csi(x, <span class="number">50</span>)</span><br><span class="line">    RR_csi100 = csi(x, <span class="number">100</span>)</span><br><span class="line">    RR_cvi = get_csi_cvi_features(x)[<span class="string">&#x27;cvi&#x27;</span>]</span><br><span class="line">    Modified_CSI10 = Modified_csi(x, <span class="number">10</span>)</span><br><span class="line">    Modified_CSI30 = Modified_csi(x, <span class="number">30</span>)</span><br><span class="line">    Modified_CSI50 = Modified_csi(x, <span class="number">50</span>)</span><br><span class="line">    Modified_CSI100 = Modified_csi(x, <span class="number">100</span>)</span><br><span class="line">    RR_apen = apen(x, m=<span class="number">2</span>, r=<span class="number">0.6</span>)</span><br><span class="line">    RR_spen = spen(x)</span><br><span class="line">    A = get_sampen(x)</span><br><span class="line">    RR_sampen = A[<span class="string">&#x27;sampen&#x27;</span>]</span><br><span class="line">    RR_lle = lle(x)</span><br><span class="line">    ALL_5 = [RR_sd1, RR_sd2, RR_sd2/RR_sd1, RR_csi10, RR_csi30, RR_csi50, RR_csi100, RR_cvi, Modified_CSI10,</span><br><span class="line">             Modified_CSI30, Modified_CSI50, Modified_CSI100, RR_apen, RR_spen, RR_sampen, RR_lle]</span><br><span class="line">    <span class="keyword">return</span> ALL_5</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">non_linear</span>(<span class="params">x</span>):</span></span><br><span class="line">    RR_sd1 = SD1(x)</span><br><span class="line">    RR_sd2 = SD2(x)</span><br><span class="line">    RR_csi10 = csi(x, <span class="number">10</span>)</span><br><span class="line">    RR_cvi = get_csi_cvi_features(x)[<span class="string">&#x27;cvi&#x27;</span>]</span><br><span class="line">    Modified_CSI10 = Modified_csi(x, <span class="number">10</span>)</span><br><span class="line">    RR_apen = apen(x, m=<span class="number">2</span>, r=<span class="number">0.6</span>)</span><br><span class="line">    RR_spen = spen(x)</span><br><span class="line">    RR_lle = lle(x)</span><br><span class="line">    RR_sampen = get_sampen(x)[<span class="string">&#x27;sampen&#x27;</span>]</span><br><span class="line">    ALL_30 = [RR_sd1, RR_sd2, RR_sd2/RR_sd1, RR_csi10, RR_cvi, Modified_CSI10, RR_apen, RR_spen, RR_lle, RR_sampen]</span><br><span class="line">    <span class="keyword">return</span> ALL_30</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time     : 2020/6/8</span></span><br><span class="line"><span class="comment"># @Author   : esy</span></span><br><span class="line"></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">Provides the non-linear functions for processing ECGs. Signals should be input</span></span><br><span class="line"><span class="string">as an np.array of R-R intervals. Arrays can be multi-dimensional as long as</span></span><br><span class="line"><span class="string">axis 1 moves through time (i.e. inputs should have shapes (n,) or (m, n)).</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">Includes function: csi (cardiac sympathatic index) apen (approximate entropy),</span></span><br><span class="line"><span class="string">spen (spectral entropy), lle (largest Lypunov exponent).</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">from</span> scipy.fftpack <span class="keyword">import</span> fft, ifft</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">csi</span>(<span class="params">intervals, num_points</span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    From Geometry of the Poincare plot of RR intervals and its asymmetry in</span></span><br><span class="line"><span class="string">    healthy adults, J. Piskorski and P. Guzik; and A new method of assessing</span></span><br><span class="line"><span class="string">    cardiac autonomic function and its comparison with spectral analysis and</span></span><br><span class="line"><span class="string">    coefficient of variation of R--R interval, Motomi Toichi, Takeshi Sugiura</span></span><br><span class="line"><span class="string">    Toshiya Murai, and Akira Sengoku.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    Cardiac Sympathetic Index (CSI). The poincare plot is method for visualizing</span></span><br><span class="line"><span class="string">    chaotic signals by plotting the peaks of a signal against the same peaks</span></span><br><span class="line"><span class="string">    delayed by one, for use with heart rate the peaks used are the R-R</span></span><br><span class="line"><span class="string">    intervals. This produces a ellipse aligned along the line x=y with major</span></span><br><span class="line"><span class="string">    and minor axes 4*SD2 and 4*SD1 respectively. The minor axis represents</span></span><br><span class="line"><span class="string">    variation between consecutive beats while the major axis represents</span></span><br><span class="line"><span class="string">    total beat difference. The CSI is given by SD2/SD1. Large CSI values</span></span><br><span class="line"><span class="string">    indicate relatively large inter-beat variation.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    Parameters:</span></span><br><span class="line"><span class="string">        num_points (positive integer): The number of datapoints used to</span></span><br><span class="line"><span class="string">        calculate the CSI. Used as a window so the output will be of length</span></span><br><span class="line"><span class="string">        len(intervals) - num_points + 1.</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line">    sd1, sd2 = _sd(intervals, num_points)</span><br><span class="line"></span><br><span class="line">    sd2[sd1 == <span class="number">0</span>] = <span class="number">1</span></span><br><span class="line">    sd1[sd1 == <span class="number">0</span>] = <span class="number">1</span></span><br><span class="line">    CSI = (sd2 / sd1).T</span><br><span class="line"><span class="comment">#     心交感指数CSI</span></span><br><span class="line"><span class="comment"># 庞加莱曲线图是一种将混沌信号可视化的方法，方法是将信号的峰值与延迟1的相同峰值相对照，用于心率。使用的峰值是R-R间隔。这会产生一个沿线x=y对齐的椭圆，长轴和短轴分别为4*sd2和4*sd1。短轴表示连续拍子之间的变化，而长轴表示总拍子差</span></span><br><span class="line"><span class="comment">#    找出最大的庞加莱曲线图</span></span><br><span class="line">    <span class="keyword">return</span> CSI.mean()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Modified_csi</span>(<span class="params">intervals, num_points</span>):</span></span><br><span class="line">    sd1, sd2 = _sd(intervals, num_points)</span><br><span class="line">    sd2[sd1 == <span class="number">0</span>] = <span class="number">1</span></span><br><span class="line">    sd1[sd1 == <span class="number">0</span>] = <span class="number">1</span></span><br><span class="line">    Modified_CSI = ((sd2 ** <span class="number">2</span>) / sd1).T</span><br><span class="line">    <span class="keyword">return</span> Modified_CSI.mean()</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_sd</span>(<span class="params">intervals, num_points</span>):</span></span><br><span class="line">    axis = _function_dimension(intervals)</span><br><span class="line"></span><br><span class="line">    signal_length = intervals.shape[axis]</span><br><span class="line">    n = signal_length - num_points + <span class="number">1</span></span><br><span class="line">    indices = np.<span class="built_in">sum</span>(np.mgrid[<span class="number">0</span>:n, <span class="number">0</span>:num_points], axis=<span class="number">0</span>)</span><br><span class="line">    <span class="keyword">if</span> axis == <span class="number">0</span>:</span><br><span class="line">        windowed_intervals = intervals[indices]</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        windowed_intervals = intervals.swapaxes(<span class="number">0</span>, axis)[indices]</span><br><span class="line"></span><br><span class="line">    x = windowed_intervals[:<span class="number">-1</span>]</span><br><span class="line">    y = windowed_intervals[<span class="number">1</span>:]</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">_means</span>(<span class="params">x, y</span>):</span></span><br><span class="line">        mean_x = x.mean(axis=<span class="number">1</span>)</span><br><span class="line">        mean_y = y.mean(axis=<span class="number">1</span>)</span><br><span class="line">        <span class="keyword">return</span>(mean_x, mean_y)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">_transpose</span>(<span class="params">vals</span>):</span></span><br><span class="line">        <span class="keyword">if</span> axis == <span class="number">0</span>:</span><br><span class="line">            <span class="keyword">return</span> vals.T</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">return</span> vals.swapaxes(<span class="number">0</span>, axis)</span><br><span class="line"></span><br><span class="line">    mean_x, mean_y = _means(x, y)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">_sd1</span>():</span></span><br><span class="line">        mean = _transpose(np.array([mean_y - mean_x]))</span><br><span class="line"></span><br><span class="line">        sd1 = np.std((x - y) + mean, axis=<span class="number">1</span>) / (<span class="number">2.0</span> ** <span class="number">0.5</span>)</span><br><span class="line">        <span class="keyword">return</span> sd1</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">_sd2</span>():</span></span><br><span class="line">        mean = _transpose(np.array([mean_x + mean_y]))</span><br><span class="line"></span><br><span class="line">        sd2 = np.std((x + y) - mean, axis=<span class="number">1</span>) / (<span class="number">2.0</span> ** <span class="number">0.5</span>)</span><br><span class="line">        <span class="keyword">return</span> sd2</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span>(_sd1(), _sd2())</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">apen</span>(<span class="params">intervals, m=<span class="number">2</span>, r=<span class="number">0.6</span></span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot; Approximate Entropy (ApEn) as described in &quot;Physiological time-series</span></span><br><span class="line"><span class="string">    analysis what does regularity quantify?&quot; by Steven M. Pingus And Ary L.</span></span><br><span class="line"><span class="string">    Goldberger.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    Vector x_i contains the ith heart rate to the (i + m - 1)th heart rate.</span></span><br><span class="line"><span class="string">    The distance between two vectors, x_i and x_j, is greater than r if</span></span><br><span class="line"><span class="string">    abs(x_i[k] - x_j[k]) &gt; r for any k = 0 ... (m - 1). A pair of vectors</span></span><br><span class="line"><span class="string">    (or groups), x_i and x_j, are said to be close if the distance between them</span></span><br><span class="line"><span class="string">    is less than r. C_i is the number of close groups of length m + 1 divided</span></span><br><span class="line"><span class="string">    by the number of close groups of length m.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    Based on the definition of distance if the ith and jth group are close</span></span><br><span class="line"><span class="string">    when using length m + 1 then they must also be close when using a length of</span></span><br><span class="line"><span class="string">    only m. Therefore C is the probability heart rate i + m is close to heart</span></span><br><span class="line"><span class="string">    rate j + m given all m heart rates in groups i and j are also close.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    ApEn = phi^(m+1)(r) - phi^m(r) where phi^m(r) is the average of natural</span></span><br><span class="line"><span class="string">    log C_i, for all i groups, calculated using a group size of m.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    Parameters:</span></span><br><span class="line"><span class="string">        m (positive int): group lengths.</span></span><br><span class="line"><span class="string">        r (float): max distance between close groups.</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line">    heart_rates = <span class="number">1</span> / intervals.astype(np.float32)</span><br><span class="line"></span><br><span class="line">    num_close_groups_m = _find_num_close_groups(heart_rates, m, r)</span><br><span class="line">    num_close_groups_m_plus_1 = _find_num_close_groups(heart_rates, m+<span class="number">1</span>, r)</span><br><span class="line">    num_close_groups_m_plus_2 = _find_num_close_groups(heart_rates, m+<span class="number">2</span>, r)</span><br><span class="line"></span><br><span class="line">    C_m = num_close_groups_m_plus_1 / num_close_groups_m[:<span class="number">-1</span>]</span><br><span class="line">    C_m_plus_1 = num_close_groups_m_plus_2 / num_close_groups_m_plus_1[:<span class="number">-1</span>]</span><br><span class="line"></span><br><span class="line">    phi = <span class="keyword">lambda</span> C: np.nanmean(np.log(C), axis=<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> phi(C_m_plus_1) - phi(C_m)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_find_num_close_groups</span>(<span class="params">heart_rates, m, r</span>):</span></span><br><span class="line">    dim = _function_dimension(heart_rates)</span><br><span class="line"></span><br><span class="line">    err_msg = <span class="string">&#x27;Group lengths must be smaller than the signal length&#x27;</span></span><br><span class="line">    <span class="keyword">assert</span> m &lt; heart_rates.shape[dim], err_msg</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> dim == <span class="number">0</span>:</span><br><span class="line">        dist_mat = _one_dim_distance_matrix(heart_rates)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        dist_mat = _multi_dim_distance_matrix(heart_rates)</span><br><span class="line"></span><br><span class="line">    far_vals = np.logical_or(np.greater(dist_mat, r), np.less(dist_mat, -r))</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> _sum_num_close_groups(far_vals, m).astype(np.float32)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_function_dimension</span>(<span class="params">x</span>):</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> <span class="built_in">len</span>(x.shape) &gt; <span class="number">1</span>:</span><br><span class="line">        <span class="keyword">return</span> <span class="number">1</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_one_dim_distance_matrix</span>(<span class="params">vals</span>):</span></span><br><span class="line">    repeats = np.tile(vals, (vals.shape[<span class="number">0</span>], <span class="number">1</span>))</span><br><span class="line">    <span class="keyword">return</span> repeats - repeats.T</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_multi_dim_distance_matrix</span>(<span class="params">vals</span>):</span></span><br><span class="line">    vals = _rotate_and_repeat(vals)</span><br><span class="line">    <span class="keyword">return</span> vals - np.swapaxes(vals, <span class="number">0</span>, <span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_rotate_and_repeat</span>(<span class="params">vals</span>):</span></span><br><span class="line">    vals = np.swapaxes(np.array([vals]), <span class="number">1</span>, <span class="number">2</span>)</span><br><span class="line">    size = vals.shape</span><br><span class="line">    new_size = (size[<span class="number">1</span>],) + size[<span class="number">1</span>:]</span><br><span class="line">    <span class="keyword">return</span> np.broadcast_to(vals, new_size)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_sum_num_close_groups</span>(<span class="params">group_dist_mat, m</span>):</span></span><br><span class="line">    <span class="keyword">return</span> np.<span class="built_in">sum</span>(_is_group_close(group_dist_mat, m), axis=<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_is_group_close</span>(<span class="params">far_vals, m</span>):</span></span><br><span class="line">    close_groups = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> str_idx <span class="keyword">in</span> <span class="built_in">range</span>(m):</span><br><span class="line">        end_idx = m - str_idx</span><br><span class="line">        close_groups += far_vals[str_idx:-end_idx, str_idx:-end_idx]</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> close_groups == <span class="number">0</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">spen</span>(<span class="params">intervals</span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot; Spectral Entropy (SpEn) is a measure of entropy based on the</span></span><br><span class="line"><span class="string">    probability mass distribution of the discreate Fourier transformation.</span></span><br><span class="line"><span class="string">    If a few frequencies dominate a signal the signal is predictable and</span></span><br><span class="line"><span class="string">    thus has a low entropy. SpEn uses log based 2 and can therefore be</span></span><br><span class="line"><span class="string">    interpreted as the min number of bits needed to encode the signals</span></span><br><span class="line"><span class="string">    power spectrum. Because of this length of the signal can affect the</span></span><br><span class="line"><span class="string">    outcome. &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line">    axis = _function_dimension(intervals)</span><br><span class="line"></span><br><span class="line">    spectrum = np.<span class="built_in">abs</span>(fft(intervals)) ** <span class="number">2</span></span><br><span class="line">    probs = spectrum / np.array([spectrum.<span class="built_in">sum</span>(axis=axis)]).T</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> - np.<span class="built_in">sum</span>(probs * np.log2(probs), axis=axis)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">lle</span>(<span class="params">intervals</span>):</span></span><br><span class="line">    <span class="string">&quot;&quot;&quot; Largest Lypunov exponent (LLE) is a measure chaos within a signal.</span></span><br><span class="line"><span class="string">    If the LLE of a signal is positive the signal is determined to be chaotic.</span></span><br><span class="line"><span class="string">    The Lypunov exponent of each dimension represents how quickly two initially</span></span><br><span class="line"><span class="string">    close points move apart from one another.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    This method of calculating the LLE is based on M. Rosenstein, J. Collins,</span></span><br><span class="line"><span class="string">    and C. De Luca&#x27;s method from &quot;A practical method for calculating largest</span></span><br><span class="line"><span class="string">    Lypunov exponents from small data sets&quot;.</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line">    dim = _function_dimension(intervals)</span><br><span class="line">    j = _calc_j_from_autocorr(intervals, dim)</span><br><span class="line">    <span class="keyword">return</span> j</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_calc_j_from_autocorr</span>(<span class="params">intervals, axis</span>):</span></span><br><span class="line"></span><br><span class="line">    Intervals = fft(intervals, axis=axis)</span><br><span class="line">    Corr = np.<span class="built_in">abs</span>(Intervals ** <span class="number">2</span>)</span><br><span class="line">    corr = ifft(Corr, axis=axis).real</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> axis <span class="keyword">is</span> <span class="number">0</span>:</span><br><span class="line">        corr = corr[:<span class="built_in">int</span>(<span class="built_in">len</span>(corr) / <span class="number">2</span>)] / corr[<span class="number">0</span>]</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        corr = corr[:, :corr.shape[<span class="number">1</span>] / <span class="number">2</span>] / np.array([corr[:, <span class="number">0</span>]]).T</span><br><span class="line"></span><br><span class="line">    diminish_factor = <span class="number">1</span> - <span class="number">1</span>/np.exp(<span class="number">1</span>)</span><br><span class="line">    lag_vals = np.<span class="built_in">abs</span>(corr - diminish_factor)</span><br><span class="line">    min_val = np.argmin(lag_vals, axis=axis)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> min_val</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><img src="https://pic.wenwen.soso.com/p/20090717/20090717191255-665709535.jpg"></p>

    </div>
</article>


                </div>
                <aside class="col-md-4 gal-left" id="sidebar">
    <!-- 此为sidebar的搜索框, 非搜索结果页面 -->
<aside id="sidebar-search">
    <div class="search hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <form class="form-inline clearfix" id="search-form" method="get"
              action="/search/index.html">
            <input type="text" name="s" class="form-control" id="searchInput" placeholder="搜索文章~" autocomplete="off">
            <button class="btn btn-danger btn-gal" type="submit">
                <i class="fa fa-search"></i>
            </button>
        </form>
    </div>
</aside>
    <aside id="sidebar-author">
    <div class="panel panel-gal" data-aos="flip-right" data-aos-duration="3000">
        <div class="panel-heading" style="text-align: center">
            <i class="fa fa-quote-left"></i>
            esy
            <i class="fa fa-quote-right"></i>
        </div>
        <div class="author-panel text-center">
            <img src="/imgs/avatar.jpg" width="140" height="140"
                 alt="个人头像" class="author-image">
            <p class="author-description"><p>esy</p>
</p>
        </div>
    </div>
</aside>
    
    <aside id="sidebar-recent_comments">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-comments"></i>
            最新评论
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush"></ul>
    </div>
</aside>
    
    <!-- 要配置好leancloud才能开启此小工具 -->
    
    
    <aside id="sidebar-recent_posts">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-refresh"></i>
            近期文章
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush">
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/05/python%20work/%E6%9C%80%E5%B0%8F%E4%BA%8C%E4%B9%98%E6%B3%95/">最小二乘法</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/05/python%20work/%E7%BB%9F%E8%AE%A1%E5%AD%A6%E4%B9%A0-%E7%AC%AC%E4%B8%80%E7%AB%A0/">统计学习--第一章</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/04/python%20work/hello-world/">Hello World</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/11/03/python%20work/%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E7%9A%84%E8%AF%84%E4%BC%B0%E6%8C%87%E6%A0%87/">分类模型的评估指标</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/10/21/python%20work/10-21-%E7%88%AC%E8%99%AB%E5%9F%BA%E7%A1%80/">10-21 爬虫基础</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/CRF%E7%9A%84%E6%95%B4%E4%BD%93%E6%B5%81%E7%A8%8B%E7%BB%93%E6%9E%9C/">CRF的整体流程结果</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/nlp-crf%E6%A8%A1%E5%9E%8B/">nlp_crf模型</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%983/">数学建模问题3</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%982/">数学建模问题2</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%981/">数学建模问题1</a>
                </span>
            </li>
            
        </ul>
    </div>
</aside>
    
    
    <aside id="sidebar-rand_posts">
    <div class="panel panel-gal recent hidden-xs" data-aos="fade-up" data-aos-duration="2000">
        <div class="panel-heading">
            <i class="fa fa-refresh"></i>
            随机文章
            <i class="fa fa-times-circle panel-remove"></i>
            <i class="fa fa-chevron-circle-up panel-toggle"></i>
        </div>
        <ul class="list-group list-group-flush">
            
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/10/21/python%20work/10-21-%E7%88%AC%E8%99%AB%E5%9F%BA%E7%A1%80/">10-21 爬虫基础</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/05/18/python%20work/VF%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">VF基础知识</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/03/19/python%20work/python-Matplotlib/">python_Matplotlib</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/03/22/python%20work/python-%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E5%8F%82%E6%95%B0%E8%AE%BE%E7%BD%AE/">python_随机森林参数设置</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/07/18/python%20work/spacy%E7%9A%84%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E5%86%8D%E5%AD%A6%E4%B9%A0/">spacy的基础知识再学习</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/02/python%20work/tensorflow2-3%E7%89%88%E6%9C%AC%E5%AE%89%E8%A3%85/">tensorflow2.3版本安装</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/09/25/python%20work/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E9%97%AE%E9%A2%983/">数学建模问题3</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/08/24/python%20work/%E6%9F%A5%E7%9C%8B%E5%8D%95%E7%8B%AC%E6%95%B0%E6%8D%AE%E4%B8%8B%E7%9A%84%E5%87%86%E7%A1%AE%E7%8E%87/">查看单独数据下的准确率</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/06/08/python%20work/%E6%A0%87%E7%AD%BE%E5%92%8C%E7%89%B9%E5%BE%81%E9%95%BF%E5%BA%A6%E5%A4%84%E7%90%86/">标签和特征长度处理</a>
                </span>
            </li>
            
            <li class="list-group-item">
                <span class="post-title">
                    <a href="/2020/07/10/python%20work/%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%9F%BA%E7%A1%80/">聊天机器人基础</a>
                </span>
            </li>
            
        </ul>
    </div>
</aside>
    
    
    <aside id="gal-sets">
        <div class="panel panel-gal hidden-xs" data-aos="fade-up" data-aos-duration="2000">
            <ul class="nav nav-pills pills-gal">

                
                <li>
                    <a href="/2020/06/08/python%20work/HRV%E7%9A%8430s%E7%89%B9%E5%BE%81%E6%8F%90%E5%8F%96/index.html#sidebar-tags" data-toggle="tab" id="tags-tab">热门标签</a>
                </li>
                
                
                <li>
                    <a href="/2020/06/08/python%20work/HRV%E7%9A%8430s%E7%89%B9%E5%BE%81%E6%8F%90%E5%8F%96/index.html#sidebar-friend-links" data-toggle="tab" id="friend-links-tab">友情链接</a>
                </li>
                
                
                <li>
                    <a href="/2020/06/08/python%20work/HRV%E7%9A%8430s%E7%89%B9%E5%BE%81%E6%8F%90%E5%8F%96/index.html#sidebar-links" data-toggle="tab" id="links-tab">个人链接</a>
                </li>
                
            </ul>
            <div class="tab-content">
                
                <div class="cloud-tags tab-pane nav bs-sidenav fade" id="sidebar-tags">
    
    <a href="/tags/py-study/" style="font-size: 9.186279598759764px;" class="tag-cloud-link">py_study</a>
    
    <a href="/tags/nlp/" style="font-size: 13.435025394268223px;" class="tag-cloud-link">nlp</a>
    
    <a href="/tags/Graduation-work/" style="font-size: 9.95753945871859px;" class="tag-cloud-link">Graduation work</a>
    
    <a href="/tags/work/" style="font-size: 15.696543682409256px;" class="tag-cloud-link">work</a>
    
    <a href="/tags/hexo/" style="font-size: 13.740440798114001px;" class="tag-cloud-link">hexo</a>
    
    <a href="/tags/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 18.70835003003566px;" class="tag-cloud-link">-个人博客搭建</a>
    
    <a href="/tags/malab-%E6%AF%95%E4%B8%9A/" style="font-size: 15.086048654323578px;" class="tag-cloud-link">-malab -毕业</a>
    
    <a href="/tags/python-%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/" style="font-size: 17.194726538797212px;" class="tag-cloud-link">-python -人工智能</a>
    
    <a href="/tags/python/" style="font-size: 10.113850344417886px;" class="tag-cloud-link">python</a>
    
    <a href="/tags/python/" style="font-size: 19.793962106000077px;" class="tag-cloud-link">-python</a>
    
    <a href="/tags/mathematical-modeling/" style="font-size: 13.293339705642062px;" class="tag-cloud-link">mathematical modeling</a>
    
    <a href="/tags/statistical-learning/" style="font-size: 17.502128491654414px;" class="tag-cloud-link">statistical learning</a>
    
</div>
                
                
                <div class="friend-links tab-pane nav bs-sidenav fade" id="sidebar-friend-links">
    
    <li>
        <a href="http://kdays.net/days/" target="_blank">KDays Forum</a>
    </li>
    
    <li>
        <a href="http://www.gal123.com/" target="_blank">绅士导航♂</a>
    </li>
    
    <li>
        <a href="http://www.moe123.com/" target="_blank">萌导航</a>
    </li>
    
</div>
                
                
                <div class="links tab-pane nav bs-sidenav fade" id="sidebar-links">
    
    <li>
        <a href="https://github.com/ZEROKISEKI/" target="_blank">Github</a>
    </li>
    
    <li>
        <a href="https://coding.net/u/SORA1" target="_blank">Coding</a>
    </li>
    
    <li>
        <a href="https://www.zhihu.com/people/aonosora/activities" target="_blank">知乎</a>
    </li>
    
</div>
                
            </div>
        </div>
    </aside>
    
</aside>
            </div>
        </div>
    </div>
    <footer id="gal-footer">
    <div class="container">
        Copyright © 2018 esy Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>.&nbsp;Theme by <a href="https://github.com/ZEROKISEKI" target="_blank">AONOSORA</a>
    </div>
</footer>

<!-- 回到顶端 -->
<div id="gal-gotop">
    <i class="fa fa-angle-up"></i>
</div>
</body>

<script src="/js/activate-power-mode.js"></script>

<script>

    // 配置highslide
	hs.graphicsDir = '/js/highslide/graphics/'
    hs.outlineType = "rounded-white";
    hs.dimmingOpacity = 0.8;
    hs.outlineWhileAnimating = true;
    hs.showCredits = false;
    hs.captionEval = "this.thumb.alt";
    hs.numberPosition = "caption";
    hs.align = "center";
    hs.transitions = ["expand", "crossfade"];
    hs.lang.number = '共%2张图, 当前是第%1张';
    hs.addSlideshow({
      interval: 5000,
      repeat: true,
      useControls: true,
      fixedControls: "fit",
      overlayOptions: {
        opacity: 0.75,
        position: "bottom center",
        hideOnMouseOut: true
      }
    })

    // 初始化aos
    AOS.init({
      duration: 1000,
      delay: 0,
      easing: 'ease-out-back'
    });

</script>
<script>
	POWERMODE.colorful = 'true';    // make power mode colorful
	POWERMODE.shake = 'true';       // turn off shake
	// TODO 这里根据具体情况修改
	document.body.addEventListener('input', POWERMODE);
</script>
<script>
    window.slideConfig = {
      prefix: '/imgs/slide/background',
      ext: 'jpg',
      maxCount: '6'
    }
</script>

<script src="/js/hs.js"></script>
<script src="/js/blog.js"></script>



<script src="/js/oni.js"></script>




</html>